bin/commit: Support committing archives from stdin
authorTristan Van Berkom <tristan.vanberkom@codethink.co.uk>
Tue, 21 May 2019 13:26:55 +0000 (22:26 +0900)
committerAtomic Bot <atomic-devel@projectatomic.io>
Tue, 28 May 2019 17:03:22 +0000 (17:03 +0000)
This commit interprets archive filenames specified as '-' to
indicate that the input should be read from stdin.

Closes: #1862
Approved by: jlebon

src/ostree/ot-builtin-commit.c

index b7c61a9e20a1621d366811b00d29d21209086de7..56f596818b6eb82543d95d4eee364f1f78cc4c45 100644 (file)
@@ -636,11 +636,22 @@ ostree_builtin_commit (int argc, char **argv, OstreeCommandInvocation *invocatio
             {
               if (!opt_tar_pathname_filter)
                 {
-                  object_to_commit = g_file_new_for_path (tree);
-                  if (!ostree_repo_write_archive_to_mtree (repo, object_to_commit, mtree, modifier,
-                                                           opt_tar_autocreate_parents,
-                                                           cancellable, error))
-                    goto out;
+                  if (strcmp (tree, "-") == 0)
+                    {
+                      if (!ostree_repo_write_archive_to_mtree_from_fd (repo, STDIN_FILENO, mtree, modifier,
+                                                                       opt_tar_autocreate_parents,
+                                                                       cancellable, error))
+                        goto out;
+                    }
+                  else
+                    {
+                      object_to_commit = g_file_new_for_path (tree);
+
+                      if (!ostree_repo_write_archive_to_mtree (repo, object_to_commit, mtree, modifier,
+                                                               opt_tar_autocreate_parents,
+                                                               cancellable, error))
+                        goto out;
+                    }
                 }
               else
                 {
@@ -666,7 +677,13 @@ ostree_builtin_commit (int argc, char **argv, OstreeCommandInvocation *invocatio
                       goto out;
                     }
                   opts.translate_pathname_user_data = &tpdata;
-                  g_autoptr(OtAutoArchiveRead) archive = ot_open_archive_read (tree, error);
+
+                  g_autoptr(OtAutoArchiveRead) archive;
+                  if (strcmp (tree, "-") == 0)
+                    archive = ot_open_archive_read_fd (STDIN_FILENO, error);
+                  else
+                    archive = ot_open_archive_read (tree, error);
+
                   if (!archive)
                     goto out;
                   if (!ostree_repo_import_archive_to_mtree (repo, &opts, archive, mtree,